package Logic;

import utils.GamerException;
import utils.IniFile;
import utils.Vec;
import irio.gamer.gamer;

public class GalaxyComponent {

	public Vec type = new Vec();

	public Vec intensity_modifier = new Vec(1,0,0);
	public Vec spectrum = new Vec(0,0,0);
	public Vec armstrength = new Vec(2,0,0);
	public Vec z0 = new Vec(0.01,0,0);
	public Vec r0 = new Vec(0.150,0,0);
	public Vec winding = new Vec(0,0,0);
	public Vec delta = new Vec(0,0,0);
	public Vec active = new Vec(1,0,0);
	public Vec scale = new Vec(1,0,0);
	public Vec noiseTilt = new Vec(1,0,0);
	public Vec noiseOffset = new Vec(0,0,0);
	public int component_no = 0;
	
	public static final String[] types = {"BULGE", "DISK", "STARS", "DUST", "CLOUDS"};
	public static final double[] typesValues = {0,1,2,3,4};
	
	
	public void Load(IniFile ini, int component) throws GamerException {
//		try {
		component_no = component+1;
		String c = "component" + (int)component_no + "_";
		String s = ini.getString(c+"type");
		for (int i=0;i<types.length;i++) {
//			System.out.println(c + "type: " +  s + " vs " + types[i]);
			if (s.equals(types[i]))
				type.x = i;
		}
	
		intensity_modifier.x = ini.getDouble(c+ "intensity_modifier");

		String spec = ini.getString(c+ "spectrum");
		spectrum.x = gamer.spectra.find(spec);
		armstrength.x = ini.getDouble(c+ "armstrength");
		z0.x = ini.getDouble(c+ "z0");
		r0.x = ini.getDouble(c+ "r0");
		if (type.x == 0) {
			z0.x = 10.0;
			r0.x = 10.0;
		}

		scale.x = ini.getDouble(c+ "scale");
		winding.x = ini.getDouble(c+ "winding");
		active.x = ini.getDouble(c+ "active");
		try {
			noiseOffset.x = ini.getDouble(c+ "noise_offset");
			noiseTilt.x = ini.getDouble(c+ "noise_tilt");
			delta.x = ini.getDouble(c+ "delta");
		} catch (GamerException ge) {
//			gamer.HandleException(ge, "Error loading galaxy "+component);
		}
	}
	
	public void Save(IniFile ini) {
		String c = "component" + (int)component_no + "_";
		ini.addSpace();
		ini.addKey(c+"type", types[(int)type.x]);
		ini.addKey(c+"intensity_modifier", intensity_modifier.x);
		ini.addKey(c+"spectrum", gamer.spectra.spectra[(int)spectrum.x]);
		ini.addKey(c+"armstrength", armstrength.x);
		ini.addKey(c+"z0", z0.x);
		ini.addKey(c+"r0", r0.x);
		ini.addKey(c+"delta", delta.x);
		ini.addKey(c+"winding", winding.x);
		ini.addKey(c+"scale", scale.x);
		ini.addKey(c+"active", (int)active.x);
		ini.addKey(c+"noise_tilt", noiseTilt.x);
		ini.addKey(c+"noise_offset", noiseOffset.x);
	}
	
}
